package com.yuw.othertools;

public class Student implements Comparable<Student> {

	// 属性
	private String stuName;
	private String stuNum;
	private double stuScore;

	// 行为
	/**
	 * 行为方法：输出学生个人信息
	 */
	public void printMe() {
		System.out.println("姓名：" + stuName + ", 学号：" + stuNum + ", 成绩：" + stuScore);
	}

	// 构造方法
	public Student() {
		super();
	}

	public Student(String stuName, String stuNum, double stuScore) {
		super();
		this.stuName = stuName;
		this.stuNum = stuNum;
		this.stuScore = stuScore;
	}

	// getter/setter方法接口

	public String getStuName() {
		return stuName;
	}

	public void setStuName(String stuName) {
		this.stuName = stuName;
	}

	public String getStuNum() {
		return stuNum;
	}

	public void setStuNum(String stuNum) {
		this.stuNum = stuNum;
	}

	public double getStuScore() {
		return stuScore;
	}

	public void setStuScore(double stuScore) {
		this.stuScore = stuScore;
	}

	@Override
	public int compareTo(Student stu) {
		// 默认返回值(相等)
		int i_re = 0;
		// 学生排序的比较（按成绩排序）
		if (stu == null) {
			// 被比较对象为null，表示大于它，返回1
			i_re = 1;
		} else if (this.getStuScore() > ((Student) stu).getStuScore()) {
			// 大于情况
			i_re = 1;
		} else if (this.getStuScore() < ((Student) stu).getStuScore()) {
			// 小于情况
			i_re = -1;
		}
		return i_re * -1;
	}

	@Override
	public boolean equals(Object anObject) {
		// 地址一样，内容肯定相同
		if (this == anObject) {
			return true;
		}
		// 判定被比较对象是不是当前类的类型
		if (anObject instanceof Student && anObject != null) {
			// 塑型，向下
			Student anotherStu = (Student) anObject;
			// 根据业务判定两个Student对象之间的内容是否相等
			if (this.getStuName().equals(anotherStu.getStuName()) 
					&& this.getStuNum().equals(anotherStu.getStuNum())) {
				// 内容相同
				return true;
			}

		}
		return false;
	}

	@Override
	public String toString() {
		return "Student [stuName=" + stuName + ", stuNum=" + stuNum + ", stuScore=" + stuScore + "]";
	}

}
